
<%@page import="com.bitzer.google.Documents"%>
<%@page import="com.bitzer.google.Utils"%>


<%@page import="java.io.IOException"%>
<%@page import="com.google.gdata.util.ServiceException"%>
<%@page import="com.google.gdata.data.docs.DocumentListFeed"%>
<%@page import="com.google.gdata.data.docs.DocumentListEntry"%>
<%@page import="java.util.List"%>

<%@page import="com.bitzer.google.Constants"%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <meta name="bitzer-component" content="data"/>


        <title>Document List</title>
    </head>
    <body>
        <%

                    String username = (String) session.getAttribute("username");
                    String password = (String) session.getAttribute("password");

                    if (username == null || username == ""
                            || password == null || password == "") {
                        response.sendRedirect(request.getContextPath()+"/login.jsp");
                    }

                    Documents documents = Documents.instance();
                    documents.authenticate(username, password);
                    String startRowStr = request.getParameter("startRow");
                    String numberOfRowsStr = request.getParameter("numberOfRows");
                    String lastModifiedOn = request.getParameter("lastModifiedOn");
                    String resource_folder_id = request.getParameter("folder_id");

                    int startRow = Utils.stringToInt(startRowStr, 1);
                    if (startRow == 0) {
                        startRow = 1;
                    }
                    int numberOfRows = Utils.stringToInt(numberOfRowsStr, 50000);
                    if (numberOfRows == 0) {
                        numberOfRows = 50000;
                    }

                    DocumentListFeed feed = documents.getDocumentListFeed(lastModifiedOn, startRow, numberOfRows,resource_folder_id);

        %>

        <table data-bitzer-data="true"
               data-bitzer-title="DocumentList"
               data-bitzer-desc="List of Documents"
               data-bitzer-component="DocumentList"
               data-bitzer-record-count="<%=documents.recordCount%>"
               data-bitzer-start-index="<%=startRow%>"
               data-bitzer-number-of-rows="<%=numberOfRows%>">
            <tr>
                <th data-bitzer-field="document_id" data-bitzer-key-order="1">id</th>
                <th data-bitzer-field="resource_folder_id">Resource Folder Id</th>
                <th data-bitzer-field="title">Title</th>
                <th data-bitzer-field="type">Type</th>
                <th data-bitzer-field="weblink">link</th>
                <th data-bitzer-field="lastModifiedOn">Last Modified</th>
            </tr>
            <%
                        try {

                            DocumentListEntry entry = null;

                             for (int i = 0; i < feed.getEntries().size(); i++) {
                                entry = feed.getEntries().get(i);
                                
                                out.print(Utils.dataRowElement("document_id", entry.getResourceId()));
                                out.print(Utils.dataCell(entry.getResourceId()));
                                out.print(Utils.dataCell(resource_folder_id));
                                out.print(Utils.dataCell(entry.getTitle().getPlainText()));
                                out.print(Utils.dataCell(entry.getType()));
                                out.print(Utils.dataCell(entry.getHtmlLink().getHref()));
                                
                                out.print(Utils.dataCell(Utils.formattedDateTime(entry.getUpdated())));
                                out.print("</tr>");
                                
                            }

                        } catch (Exception e) {
                            e.printStackTrace();
                        }

            %>



        </table>

    </body>
</html>
